class Solution {
public:
    string addStrings(string num1, string num2) {
        string s;
        int size1 = num1.size() - 1, size2 = num2.size() - 1;
        int next = 0;
        while (size1 >= 0 || size2 >= 0)
        {
            int a = size1 >= 0 ? num1[size1] - '0' : 0;
            int b = size2 >= 0 ? num2[size2] - '0' : 0;
            char ret = (a + b + next) % 10 + '0';
            next = (a + b + next) / 10;
            s.push_back(ret);
            size1--;
            size2--;
        }
        if (next == 1)
        {
            s.push_back('1');
        }
        reverse(s.begin(), s.end());
        return s;
    }


    string multiply(string num1, string num2) {
        if (num1[0] == '0' || num2[0] == '0')
            return "0";
        string s = "0";
        int snum1 = num1.size() - 1, snum2 = num2.size() - 1;
        int next = 0;
        string s2;
        int size = num1.size();
        while (snum1 >= 0)
        {
            next = 0;
            int a = num1[snum1] - '0';
            while (snum2 >= 0)
            {

                int b = num2[snum2] - '0';
                char ret = (a * b + next) % 10 + '0';
                next = (a * b + next) / 10;
                s2.push_back(ret);
                snum2--;
            }
            snum2 = num2.size() - 1;
            if (next > 0)
                s2.push_back(next + '0');
            reverse(s2.begin(), s2.end());
            //cout<<s2<<"  ";
            for (int i = size; i < num1.size(); i++)
                s2.push_back('0');
            size--;
            cout << s2 << "  ";
            s = addStrings(s, s2);
            snum1--;
            s2.clear();
        }
        return s;
    }
};